/**
 * 
 */
package com.example.gametestproject;

import com.xxxx.game.*;

import android.graphics.Color;
import android.graphics.PointF;

/**
 * @author HuXiaolong
 *
 */
public class ScoreSprite extends TextSprite
{
	public final static int max_live_time = 25;
	private boolean mIsLiving = true;
	
	public ScoreSprite(String txt, PointF ptStart, PointF ptEnd)
	{
		super(txt, 10, Color.argb(255, 0, 255, 0), Color.argb(255, 0xcc, 0xcc, 0xcc), Color.argb(255, 255, 255, 0), 
				5, 3, TextSprite.HorizontalAlignment.AlignCenter, TextSprite.VerticalAlignment.AlignTop);
		//this.setAlpha(128);
		LinearPath lPath = new LinearPath(ptStart, ptEnd, max_live_time - max_live_time / 4);
		LinearPath lpath2 = new LinearPath(ptEnd, new PointF(0, 0), max_live_time / 4);
		lPath.append(lpath2);
		
		CompactAnimation ca = new CompactAnimation();
		ca.add(lPath);
		ca.add(this.mScaleAnimation);
		this.setSpriteAnimation(ca);
		
		this.setZOrder(200);
	}
	
	private IAnimation mScaleAnimation = new AnimationBasic()
	{
		public int mLeftTime = ScoreSprite.max_live_time;
		
		@Override
		public boolean update(ISprite sprite)
		{
			if (mLeftTime <= 0) 
			{
				sprite.makedead();
				return false;
			}
			ScoreSprite ss = (ScoreSprite)sprite;
			if (mLeftTime >= 14)
			{
				ss.setTextSize(ss.getTextSize() + 1);
			}
			else if (mLeftTime >= 8)
			{
				ss.setTextSize(ss.getTextSize() - 1);
			}
			if (mLeftTime >= max_live_time / 2)
			{
				ss.getPaint().setAlpha(255 * mLeftTime / (max_live_time / 2));
			}
			else
			{
				ss.getPaint().setAlpha(255 - 255 * mLeftTime / (max_live_time / 2));
			}
			
			
			if (--mLeftTime > 0) return true;
			sprite.makedead();
			return false;
		}

		@Override
		public String getName()
		{
			return "ScoreScale";
		}

		@Override
		public boolean isMoving()
		{
			return false;
		}
	};
	
	@Override
	public boolean isLiving()
	{
		return mIsLiving;
	}

	@Override
	public void makedead()
	{
		mIsLiving = false;
	}
}
